package com.liesheng.haylou.view.dialog;


import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.liesheng.haylou.R;


/**
 * Date:2019/11/15
 * <p>
 * Author:wuzhiguang
 * <p>
 * Description:
 * 确定样式Dialog
 */
public class ConfirmDialog extends BaseDialog {


    private int title = R.string.dialog_title, message = R.string.dialog_msg, cancelText = R.string.dialog_cancel, submitText = R.string.dialog_submit;
    private SubmitOnclickListener submitOnClickListener;

    private ConfirmDialog() {
        setSize(MATCH_CONTENT_MARGIN, WRAP_CONTENT);
    }

    public static ConfirmDialog newInstance() {
        ConfirmDialog dialog = new ConfirmDialog();
        return dialog;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle == null) {
            return;
        }
    }

    @Override
    public int setUpLayoutId() {
        return R.layout.dialog_confirm;
    }

    @Override
    public void convertView(ViewHolder holder, final BaseDialog dialog) {
        holder.setText(R.id.title, title);
        holder.setText(R.id.message, message);
        holder.setText(R.id.btn_cancel, cancelText);
        holder.setText(R.id.btn_submit, submitText);

        holder.setOnClickListener(R.id.btn_cancel, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        holder.setOnClickListener(R.id.btn_submit, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if (submitOnClickListener != null)
                    submitOnClickListener.onSubmit();
            }
        });
    }

    public ConfirmDialog setTitle(int title) {
        this.title = title;
        return this;
    }

    public ConfirmDialog setMessage(int msg) {
        this.message = msg;
        return this;
    }


    public ConfirmDialog setCancelText(int cancelText) {
        this.cancelText = cancelText;
        return this;
    }

    public ConfirmDialog setSubmitText(int submitText) {
        this.submitText = submitText;
        return this;
    }

    public ConfirmDialog setSubmitOnclickListener(SubmitOnclickListener onclickListener) {
        this.submitOnClickListener = onclickListener;
        return this;
    }

    public interface SubmitOnclickListener {
        void onSubmit();
    }
}